package org.digital.entity.domain;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import org.digital.common.Modbus;

import java.util.Date;
@Data
@TableName("digital_tags")
public class Tag {
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    @TableField("group_id")
    private Integer groupId;

    private String name;

    private String unit;

    private Integer start;

    private Integer code;

    private Integer decimal;

    private Integer type; // 数据类型

    @TableField(exist = false)
    private Modbus.DATATYPE typeWith;

    private Date createdAt;

    private Date updatedAt;
    @TableLogic
    private Date deletedAt;


    public void setTypeWith(Modbus.DATATYPE value) {
        type = value.getValue();
        typeWith = value;
    }

    public void setType(Integer value){
        type = value;
        for(Modbus.DATATYPE item : Modbus.DATATYPE.values()){
            if(item.getValue() == value){
                typeWith = item;
            }
        }
    }

}
